/**
 * 仓库出入库管理公用方法
 *
 *
 */
import moment from 'moment'
export default {
  methods: {
    addAfter(data) {
      data ? this.form = Object.assign({}, data) : ''
      this.form.orderDate = moment().format('YYYY-MM-DD')
      new Promise(() => {
        this.form.code = '1111'
      })
    },
    // batchChange({ selectRows, row }) {
    //   if (selectRows && selectRows.length > 0) {
    //     selectRows.forEach((item, i) => {
    //       if (i === 0) {
    //         row.batch = item.batch
    //         row.number = item.number
    //       } else {
    //         this.$refs[this.refKeys[0]].insert({
    //           itemName: row.itemName,
    //           mCode: row.itemCode,
    //           batch: item.batch,
    //           number: item.number
    //         })
    //       }
    //     })
    //   } else {
    //     row.itemName = ''
    //     row.mCode = ''
    //   }
    // },
    materialChange({ selectRows, row }) {
      if (selectRows && selectRows.length > 0) {
        selectRows.forEach((item, i) => {
          if (i === 0) {
            row.itemName = item.itemName
            row.mCode = item.itemCode
          } else {
            this.$refs[this.refKeys[0]].insert({
              itemName: item.itemName,
              mCode: item.itemCode
            })
          }
        })
      } else {
        row.itemName = ''
        row.mCode = ''
      }
    },
    handleBatchDetailed(row) {
      this.$refs.zBatchDetailed.show(row.batch || [])
    },
    handleBatchSelect(row) {
      this.$refs.zSelectBatchList.show({
        mCode: row.mCode,
        table: this.$refs[this.refKeys[0]],
        currentRow: row
      })
    },
    batchChange({ selectRows, row }) {
      row.batch = selectRows
    }
  }
}

